package com.cyw.search.controller;

import cn.easyes.core.biz.PageInfo;
import com.cyw.common.core.controller.BaseController;
import com.cyw.common.core.domain.R;
import com.cyw.search.entity.note.SearchNoteEntity;
import com.cyw.search.service.SearchNoteEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Chenyw
 * @Date: 2022/08/21/22:21
 */
@Api(value = "文章接口", tags = {"文章接口"})
@RestController
@RequestMapping("/search/note")
public class EsNoteController extends BaseController {

    @Resource
    private SearchNoteEntityService searchNoteEntityService;

    @ApiOperation("高亮全局搜索")
    @GetMapping("searchAllNote")
    public R<PageInfo<SearchNoteEntity>> searchAllNote(@ApiParam("输入内容") @RequestParam(value = "searchText", defaultValue = "") String searchText,
                                                       @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                       @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
            return searchNoteEntityService.searchAllNote(searchText,pageNum,pageSize);
    }

    @ApiOperation("根据id查询文章")
    @GetMapping("findNoteById/{id}")
    public R<SearchNoteEntity> findById(@PathVariable String id){
        return R.ok(searchNoteEntityService.findById(id));
    }

    @ApiOperation("查询热门文章(3篇)")
    @GetMapping("findHotNote")
    public R<List<SearchNoteEntity>> findHotNote(){
        return R.ok(searchNoteEntityService.findHotNote());
    }

    @ApiOperation("查询所有文章")
    @GetMapping("findAllNote")
    public R<PageInfo<SearchNoteEntity>> findAllNote( @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                  @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return searchNoteEntityService.findAllNote(pageNum,pageSize);
    }

    @ApiOperation("写文章")
    @PostMapping("writeNote")
    public R writeNote(@RequestBody SearchNoteEntity searchNoteEntity){
    System.out.println(searchNoteEntity);
        searchNoteEntityService.writeNote(searchNoteEntity);
        return R.ok();
    }

}
